package com.cares.core.mng.service;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;


import com.cares.core.utils.StringUtil;
import com.cares.entity.mng.LoginToken;

/**
 * 
 * @author ZZW
 * 
 */
public class AuthenticationFilter extends FormAuthenticationFilter {
	public static final String DEFAULT_LOCALE_PARAM = "locale";

	private String localeParam = DEFAULT_LOCALE_PARAM;

	protected String getLocale(ServletRequest request) {
		//return WebUtils.getCleanParam(request, getLocaleParam());
		return "";

	}

	protected AuthenticationToken createToken(ServletRequest request,
			ServletResponse response) {

		String username = super.getUsername(request);
		String password = super.getPassword(request)+"";
		String locale = this.getLocale(request);
		boolean rememberMe = super.isRememberMe(request);
		String host = super.getHost(request);
		if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
			return null;
		} else {

			return new LoginToken(username, password.toCharArray(), rememberMe,
					host, locale);
		}

	}

	public String getLocaleParam() {
		return localeParam;
	}

}
